﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Client;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;

namespace BrokerBase.Lib.Tool
{
    public class OfficeExist
    {
        public int ExistsRegedit()
        {
            int ifused = 0;
            RegistryKey rk = Registry.LocalMachine;
            RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\11.0\Excel\InstallRoot\");//查询2003

            RegistryKey akey07 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot\");//查询2007

            RegistryKey akey10 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot\");//查询2010
            //RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\Kingsoft\Office\6.0\common\");//查询wps
            //检查本机是否安装Office2003
            if (akey != null)
            {
                string file03 = akey.GetValue("Path").ToString();
                if (File.Exists(file03 + "Excel.exe"))
                {
                    ifused += 1;
                }
            }

            //检查本机是否安装Office2007

            if (akey07 != null)
            {
                string file07 = akey07.GetValue("Path").ToString();
                if (File.Exists(file07 + "Excel.exe"))
                {
                    ifused += 2;
                }
            }

            if (akey10 != null)
            {
                string file10 = akey10.GetValue("Path").ToString();
                if (File.Exists(file10 + "Excel.exe"))
                {
                    ifused += 3;
                }
            }
            ////检查本机是否安装wps
            //if (akeytwo != null)
            //{
            //    string filewps = akeytwo.GetValue("InstallRoot").ToString();
            //    if (File.Exists(filewps + @"\office6\et.exe"))
            //    {
            //        ifused += 4;
            //    }
            //}
            return ifused;
        }

        

        public bool CodeboolisWordInstalled()
        {
            Type type = Type.GetTypeFromProgID("Word.Application");
            if (type == null)
            {
                return false;
            }
            return true;
        }
    }

}
